<template>
    <div  class="prov-container">
        
        <!-- 查询表单 -->
        <el-form :inline="true">
            <el-form-item>
                <el-autocomplete
                    v-model="searchObj.fpid"
                    :fetch-suggestions="querySearch"
                    :trigger-on-focus="false"
                    class="inline-input"
                    placeholder="供应商编号"
                    value-key="fpid" />
            </el-form-item>
            <el-form-item>
                <el-autocomplete
                v-model="searchObj.fpname"
                :fetch-suggestions="querySearch"
                :trigger-on-focus="false"
                class="inline-input"
                placeholder="供应商名称"
                value-key="fpname" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="fetchData()">查询</el-button>
                <el-button type="default" @click="resetData()">清空</el-button>
            </el-form-item>
        </el-form>
        
        <el-button type="primary" @click.native="vueCreate">创建供应商</el-button>
        <el-button type="primary" @click.native="vueCreate">导入Excel</el-button>
        <el-button type="primary" @click.native="vueCreate">导出Excel</el-button>
        <provinfo :dialogFormVisible="dialogFormVisible"  :updateOrCreate="updateOrCreate" :editProvInfo="editProvInfo" />
        <!-- 表单部分 -->
        <el-table
            :data="provList"
            style="width: 100%"
        >
            <el-table-column
                prop="fpid"
                label="供应商编号"
                width="120"
                sortable
                />
            <el-table-column
                prop="fpname"
                label="供应商名称"
                width="150"
                sortable
                />
            <el-table-column
                prop="fpcontacts"
                label="联系人"
                width="100"
                sortable
                />
            <el-table-column
                prop="fptel"
                label="联系电话"
                width="150"
                sortable
                />
            <el-table-column
                prop="fpfax"
                label="传真号"
                width="100"
                sortable
                />
            <el-table-column
                prop="fpaddr"
                label="地址"
                width="150"
                sortable
                />
            <el-table-column
                prop="fpmemo"
                label="备注"
                width="200"
                sortable
                />
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="primary" size="big" @click="vueDelete(scope.row.fpid)">删除</el-button>
                    <el-button type="primary" size="big"  @click="vueEdit(scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 50, 100, 200]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="200">
        </el-pagination>
    </div>
</template>
<script>
import { getProvList, deleteProv } from  '@/api/prov'
import provinfo from '@/views/purchase/provider/components/ProvInfo'

export default {
    components: {
        provinfo
    },
    data () {
        return {
            provList: {},
            searchObj: {},
            dialogFormVisible: false,
            /*true 代表更新，false代表创建*/
            updateOrCreate: false,
            editProvInfo: {}
            
        }
    },
    created() {
        this.fetchData()
    },
    methods: {
        vueCreate() {
            this.dialogFormVisible=true
            this.updateOrCreate=false
        },
        vueEdit(row) {
            this.dialogFormVisible=true
            this.updateOrCreate=true
            this.editProvInfo=row
        },
        vueReset() {
            this.dialogFormVisible=false
            this.updateOrCreate=false
            this.editProvInfo={}
        },
        vueDelete(fpid) {
            this.$confirm('此操作将永久删除，受否继续？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteProv(fpid).then(response => {
                    this.fetchData()
                    this.$message({
                        type: 'success',
                        message: '删除成功'
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
        },
        fetchData() {
            getProvList(this.searchObj).then(response => {
                this.provList = response.data.provList
            })
        },
        resetData() {
            this.searchObj = {}
        }
    }

}
</script>
<style lang="scss" scoped>
    .prov-container {
      margin: 10px 50px 0;
      overflow: hidden;
    }
</style>